/*
ID:ning yusui
LANG:C++
TASK:heritage
*/
#include <iostream>  
#include <fstream>  
#include <string>  
using namespace std;

ifstream fin("heritage.in");
ofstream fout("heritage.out"); 

void BinaryTreeFromOrderings(const string & inorder, const string & preorder)
{
	if(inorder.empty())
	{
		return;
	}
	int rootIndex=	inorder.find(preorder[0]);
	//Left
	BinaryTreeFromOrderings(inorder.substr(0,rootIndex), preorder.substr(1,rootIndex+1));
	//Right
	BinaryTreeFromOrderings(inorder.substr(rootIndex+1), preorder.substr(rootIndex+1));
	fout<<preorder[0];
	return;
}


int main(int argc, char* argv[])
{
	string inorder;
	string preorder;
	fin>>inorder>>preorder;
	BinaryTreeFromOrderings(inorder, preorder);
	fout<<endl;
	return 0;
}